package com.demo.sort;

import java.util.*;

public class ObjectSort {
//    private static List<User> ArrayList;

    public static void main(String args[]){
        List<User> list = new ArrayList<User>();
        User u1 = new User();
        u1.setName("u1");
        u1.setAge(10);
        u1.setBirthday(new Date());
        for (int i = 0; i <1000 ; i++) {
            System.out.print("1");
        }
        System.out.println();
        User u2 = new User();
        u2.setName("u3");
        u2.setAge(20);
        u2.setBirthday(new Date());
        for (int i = 0; i <1000 ; i++) {
            System.out.print("1");
        }
        User u3 = new User();
        u3.setName("u3");
        u3.setAge(30);
        u3.setBirthday(new Date());
        list.add(u1);
        list.add(u2);
        list.add(u3);
        System.out.println();
        System.out.println("开始的list： "+list);
        System.out.println("开始排序。。。。。。");

        //时间的比较，集合中根据对象中的某一个属性进行比较
        //时间的比较方法时通过after或者是before进行比较
        Collections.sort(list,new Comparator<User>(){
            public int compare(User o1, User o2){
                if(o1.getBirthday().before(o2.getBirthday())){
                    return 1;
                }
                return -1;
            }
        });
        System.out.print("排序后："+list);
        System.out.println(list.get(0));
    }
}
